package com.example.productserver.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.example.productserver.entity.Product;
import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

/**
 * @author whx
 * @date 2022/4/30
 */
@LocalTCC
public interface IProductTccService extends IService<Product>{

    /**
     * @TwoPhaseBusinessAction 描述⼆阶段提交
     * name: 为 tcc⽅法的 bean 名称，需要全局唯⼀，⼀般写⽅法名即可
     * commitMethod: Commit/Confirm⽅法的⽅法名
     * rollbackMethod: Rollback/Cancel⽅法的⽅法名
     * @BusinessActionContextParamete 该注解可以将参数传递给声明的commitMethod和rollbackMethod，通过BusinessActionContext 获取。
     */
    @TwoPhaseBusinessAction(name = "reduceInventory", commitMethod = "reduceCommit", rollbackMethod = "reduceRollBack")
    String reduceInventory(@BusinessActionContextParameter(paramName = "productId") Long id,
                         @BusinessActionContextParameter(paramName = "number") Integer number);

    boolean reduceCommit(BusinessActionContext context);

    boolean reduceRollBack(BusinessActionContext context);

}
